# Maintainer: David Runge <dvzrv@archlinux.org>

_name=calmjs.parse
pkgname=python-calmjs.parse
pkgver=1.3.0
pkgrel=4
pkgdesc="Various parsers for ECMA standards"
arch=('any')
url="https://github.com/calmjs/calmjs.parse"
license=('MIT')
depends=('python-ply=3.11')
makedepends=('python-setuptools')
checkdepends=('python-pytest')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/${_name}/${_name}-${pkgver}.zip")
sha512sums=('6e62611039472867051e0d57973ebf2904d252fc37bae591ffdc172ac8a7f0a28dbedc88b0818b593d06e3cfdecd37bf40759132414e2ac9685efd56bdf007db')
b2sums=('d51c5dac7f2083c41f4969dcf236e26428e77a67dc2b4feeec6e9ed79f9930ea4977db1208fbd02e47ccba20257657d66d2afed17db413bb1a1129a3d16fc037')

prepare() {
  mv -v "${_name}-${pkgver}" "$pkgname-$pkgver"
  cd "$pkgname-$pkgver"
  # generate symbol tables required for lex and yacc
  # this requires version pinning towards python-ply!
  PYTHONPATH="src:${PYTHONPATH}" \
  python -m calmjs.parse.parsers.optimize
}

build() {
  cd "$pkgname-$pkgver"
  python setup.py build
}

check() {
  cd "$pkgname-$pkgver"
  export PYTHONPATH="build:${PYTHONPATH}"
  PYTHONDONTWRITEBYTECODE=1 pytest -v
}

package() {
  cd "$pkgname-$pkgver"
  python setup.py install --optimize=1 --root="${pkgdir}"
  install -vDm 644 {CHANGES,README}.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -vDm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
